

<%@page import="com.solution.admin.order.constants.OrderConstants"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sl" tagdir="/WEB-INF/tags" %>
<%@page import="com.solution.common.config.PublicConfig"%>
<%@page import="com.solution.common.constants.PublicStatus"%>
<%@page import="com.solution.admin.home.constants.IndexConstants"%>
<%
	String basePath = PublicConfig.ROOT_PATH;
	String imgRootURL = PublicConfig.IMG_ROOT_URL;
%>	
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>上传合同</title>
<link rel="stylesheet" type="text/css" href="<%=basePath%>/statics_wx/css/style.css">
<script src="<%=basePath%>/statics_wx/js/jquery.min.js"></script>
<script src="<%=basePath%>/statics_wx/js/js.js"></script>
<script type="text/javascript" src="<%=basePath%>/statics/plugins/upload/ajaxfileupload.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script type="text/javascript" src="<%=basePath%>/statics/plugins/layer/layer.js"></script>
<script type="text/javascript">
	//系统域名 
	var rootPath = '<%=basePath%>';
	// 系统上传文件展示域名
	var imgRootURL = '<%=imgRootURL%>';
</script>
<script>
	$(function(){
		
		var account_id = '';
		$('.bank_list11 dl dt').click(function(){
			account_id = $(this).find("#account_id").val();
			$(this).addClass('checked');
			$(this).siblings().removeClass('checked');
		});
		
		// 确认上传合同
		$("#btn_upload_contract").click(function(){
			var order_code = $("#order_code").val();
			var intro = $("#intro").val();
			var img_num = $("div.upload_picpart").find("img:gt(0)").length;
			if(img_num == 0){
				layer.msg('请上合同附件',{time:1000});
				return false;
			}
			
			var imgs = [];
			$("div.upload_picpart").find("img:gt(0)").each(function(){
				imgs.push($(this).attr("src").replace(imgRootURL,""));
			});
			
			
			var url = rootPath + "/wx/order/uploadOrderContract";
			var params = {
				orderCode : order_code,
				contractImagePath: imgs.join(","),
				intro : intro
			};
			$.ajax({
				type : "post",
				url : url,
				data : params,
				datatype : "json",
				success : function(json) {
					if(json && json.resultCode == 1){
						layer.msg('合同上传成功',{time:1000});
						// 跳转订单列表页面
						setTimeout(function(){
							window.location.href = rootPath+"/wx/order/list";
						},1000);
					}else{
						layer.msg('合同上传失败',{time:1000});
					}
				},
				error : function() {
					layer.msg('合同上传失败',{time:1000});
				}
			});
		});

		var btn_upload_contract_image = $("#btn_upload_contract_image");
		btn_upload_contract_image.click(function(){
			$("#upload_contract").click();
		});

		/*
		//微信图片上传,IOS有问题
		wx.config({
			debug : false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
			appId : $('#appId').val(), // 必填，公众号的唯一标识
			timestamp : $('#timestamp').val(), // 必填，生成签名的时间戳
			nonceStr : $('#nonceStr').val(), // 必填，生成签名的随机串
			signature : $('#signature').val(),// 必填，签名
			jsApiList : [ 'chooseImage', 'uploadImage' ] // 必填，需要使用的JS接口列表，所有JS接口列表
		});
		
		wx.ready(function(){
			btn_upload_contract_image.on('click', function() {
				takePicture($(this));
			})
		});
		*/
	});
	
	/**
	* 拍照
	*/
	function takePicture(this_){
		wx.chooseImage({
			count: 1, // 默认9
			sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
			sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
			success: function (res) {
				var localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
				wx.uploadImage({
					localId: localIds.toString(), // 需要上传的图片的本地ID，由chooseImage接口获得
					isShowProgressTips: 1, // 默认为1，显示进度提示
					success: function (res) {
						var mediaId = res.serverId; // 返回图片的服务器端ID，即mediaId
						//将获取到的 mediaId 传入后台 方法
						$.post(rootPath + "/wx/upload/picture", { mediaId : mediaId }, 
							function(res) {
								if (res.resultCode == '1') {
									var img = "<div class=\"mypic\">"+
	                        						"<img src=\""+imgRootURL+res.filePath+"\"/>"+
	                        					    "<a href=\"javascript:void(0)\" class=\"icon_close\"></a>"+
	                        				   "</div>";
									this_.closest("div.upload_picpart").append($(img));
									this_.closest("div.upload_picpart").find("a.icon_close").each(function(){
										$(this).click(function(){
											$(this).closest("div.mypic").remove();
											countImage("btn_upload_contract_image");
										});
									});
									countImage("btn_upload_contract_image");
								} else {
									layer.msg(res.resultMsg,{time:1000});
								}
							})
					},
					fail : function(res) {
						layer.msg('上传图片失败，请重试',{time:1000});
					}
				});
			}
		});
	}
	
	//微信图片预览
	function imageView(this_) {
		var src = $(this_).attr("data-src");
		var srcPre = src+'?x-oss-process=image/resize,m_pad,h_60,w_60';
		wx.previewImage({  
            current: srcPre, // 当前显示图片的http链接  
            urls: [src] // 需要预览的图片http链接列表  
        }) 
	}

	/**
	 * H5通过ajax提交图片
	 */
	function ajaxFileUpload(obj) {
		var id = $(obj).attr("id");
		var check = imageCheck(obj);
		if (!check) {
			return;
		}
		$.ajaxFileUpload({
			url: rootPath + '/uploadFile/uploadOneFile',
//			url:  rootPath + "/test/upload",
			secureuri: false,
			fileElementId: id, // input标签id属性值
			dataType: 'json',
			success: function(data, status) {
				if(data.code == 1) {
					var img = "<div class=\"mypic\">"+
            						"<img src=\""+imgRootURL+data.filePath+"?x-oss-process=image/resize,m_pad,h_60,w_60\" data-src=\""+imgRootURL+data.filePath+"\" onclick=\"imageView(this);\"/>"+
            					    "<a href=\"javascript:void(0)\" class=\"icon_close\"></a>"+
            				   "</div>";
					$("#btn_upload_contract_image").closest("div.upload_picpart").append($(img));
					$("#btn_upload_contract_image").closest("div.upload_picpart").find("a.icon_close").each(function(){
						$(this).click(function(){
							$(this).closest("div.mypic").remove();
							countImage("btn_upload_contract_image");
						});
					});
					countImage("btn_upload_contract_image");
				} else {
					layer.msg(data.msg,{time:1000});
				}
			},
			error: function(data, status, e) {
				layer.msg('上传图片失败，请重试',{time:1000});
			}
		});
	}

	//检查图片格式及大小
	function imageCheck(obj){
		var id = $(obj).attr("id");
		var filePath = $("#"+id).val();
		//检查后缀
		var ext = filePath.substring(filePath.lastIndexOf("."), filePath.length).toUpperCase();
		if (ext != ".BMP" && ext != ".PNG" && ext != ".GIF" && ext != ".JPG" && ext != ".JPEG") {
			layer.msg('只能上传图片',{time:500});
			return false;
		}
		var file_size = 0;
		if (false || !!document.documentMode) {
			var img = new Image();
			img.src = filepath;
			while (true) {
				if (img.fileSize > 0) {
					if (img.fileSize > 5 * 1024 * 1024) {
						layer.msg('图片不能大于5MB',{time:1000});
						return false;
					}
					break;
				}
			}
		} else {
			file_size = obj.files[0].size;
			var size = file_size / 1024;
			if (size > 5120) {
				layer.msg('图片不能大于5MB',{time:1000});
				return false;
			}
		}
		return true;
	}

	//图片计数
	function countImage(btn_id) {
		var imageNum = $("#"+btn_id).closest(".upload_picpart").find(".mypic").length;
		if (imageNum > 1) {
			$("#"+btn_id).attr("src",rootPath+"/statics_wx/images/upload_pic2.png");
		} else {
			$("#"+btn_id).attr("src",rootPath+"/statics_wx/images/upload_pic1.png");
		}
	}
</script>

</head>
<body style="background:#f5f5f5">
<input type="hidden" id="appId" value="${appId }"/>
<input type="hidden" id="timestamp" value="${timestamp }"/>
<input type="hidden" id="nonceStr" value="${nonceStr }"/>
<input type="hidden" id="signature" value="${signature }"/>

<input type="hidden"  id="order_code" value="${orderCode}"/>
<c:set var="rootPath" value="<%=basePath %>"></c:set>
<c:set var="imgRootURL" value="<%=imgRootURL %>"></c:set>
	<div class="yf_info1">
		<p>
			应付款: <b>￥<em><sl:nformat num="${realPayMoney}" type="2" format="#.00"/></em><sl:nformat num="${realPayMoney}" type="3" format="#.00"/>
			</b>
		</p>
	</div>
	<div class="order_info12">
		<div class="bd">
			<div class="zf_way zf_way1">
				<ul>
					<%--对公银行转账 --%>
					<li class="checked">
						<div class="upload_picpart">
	                    	<div class="mypic">
	                        	<img id="btn_upload_contract_image" src="${rootPath}/statics_wx/images/upload_pic1.png" alt="上传合同" />
	                        	<div style="display:none">
									<input type="file" name="upload" id="upload_contract" accept="image/*" onchange="ajaxFileUpload(this);" />
								</div>
	                        </div>
	                    </div>
					</li>
				</ul>
			</div>
		</div>
	</div>
	<div class="cancel_part">
		<dl>
	        <dt>
	        	<div class="textarea2">
	            	<div class="textarea2_con">
	                	<textarea id="intro" placeholder="请输入备注理由"></textarea>
	                    <b><em id="txtLen">0</em>/50</b>
	                </div>
	            </div>
	        </dt>
	    </dl>
	</div>
	<div class="footerfixed3"></div>
	<div class="footer">
		<div class="order_bottom">
			<ul>
				<li></li>
				<li><a href="javascript:void(0)" id="btn_upload_contract" class="btn1">确认上传</a></li>
			</ul>
		</div>
	</div>
</body>
</html>